<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>
        报修管理
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../css/main.css" media="all">
    <link rel="stylesheet" href="../../css/bootstrap.css">
</head>
<style>
    .layui-form-label{
        padding: 8px 0px !important;
    }
    table tr th,table tr td{
        text-align: center !important;
    }
</style>
<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
              <a><cite>首页</cite></a>
              <a><cite>服务管理</cite></a>
              <a><cite>报修列表</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"  href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <form class="layui-form x-center" action="" style="width:100%">
        <div class="layui-form-pane" style="margin-top: 15px;">
            <div class="layui-form-item">
                <input type="hidden" name="url" value="repairlist">
                <input type="hidden" name="typeId" value="1">
                <label class="layui-form-label">请选择：</label>
                <div class="layui-input-inline">
                    <select name="searchType" id="searchType" style="display:none;text-align: center">
                        <option value="-1">--请选择--</option>
                        <option value="1" <c:if test="${searchType == 1}">selected</c:if>>提出人</option>
                        <option value="2" <c:if test="${searchType == 2}">selected</c:if>>处理人</option>
                        <option value="3" <c:if test="${searchType == 3}">selected</c:if>>维修人员</option>
                    </select>
                </div>
                <div class="layui-input-inline">
                    <input type="text" name="userName"  placeholder="姓名" autocomplete="off" class="layui-input" disabled value="${userName}">
                </div>
                <label class="layui-form-label">处理结果:</label>
                <div class="layui-input-inline">
                    <select name="status" id="status" style="display:none;">
                        <option value="-1">--请选择--</option>
                        <option value="0" <c:if test="${status == 0}">selected</c:if>>未处理</option>
                        <option value="1" <c:if test="${status == 1}">selected</c:if>>处理中</option>
                        <option value="2" <c:if test="${status == 2}">selected</c:if>>已完成</option>
                    </select>
                </div>
                <div class="layui-input-inline" style="width:80px">
                    <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                </div>
            </div>
        </div>
    </form>

    <xblock>
        <button class="layui-btn layui-btn-danger" onclick="delAll()">
            <i class="layui-icon">&#xe640;</i>批量删除
        </button>
        <button class="layui-btn layui-btn-warm" onclick="downLoadFile()">
            <i class="layui-icon">&#xe61e;</i>导出
        </button>
        <span class="x-right" style="line-height:40px">共有数据：<span class="layui-badge">${pageInfo.total}</span> 条</span>
    </xblock>
    <div style="height: 448px;">
        <table class="layui-table" id="repairList">
            <thead>
            <tr>
                <th class="noExl" style="width: 80px"><input id="checkedAll" type="checkbox" name="" value=""></th>
                <th style="width: 80px">ID</th>
                <th>保修描述</th>
                <th style="width: 120px">发起人</th>
                <th style="width: 120px">处理人</th>
                <th style="width: 120px">维修人</th>
                <th style="width: 300px">发起时间</th>
                <th style="width: 150px">处理状态</th>
                <th class="noExl" style="width: 80px">操作</th>
            </tr>
            </thead>
            <tbody>
                <c:if test="${not empty pageInfo.list}">
                    <c:forEach items="${pageInfo.list}" var="exception">
                        <tr>
                            <td><input type="checkbox" value="${exception.id}"></td>
                            <td>${exception.id}</td>
                            <td>${exception.describes}</td>
                            <td>${exception.sponsor.name}</td>
                            <td>
                                <c:if test="${not empty exception.handler}">${exception.handler.name}</c:if>
                                <c:if test="${empty exception.handler}"><span style="color: #ababab">待分配</span></c:if>
                            </td>
                            <td>
                                <c:if test="${not empty exception.laborer}">${exception.laborer.name}</c:if>
                                <c:if test="${empty exception.laborer}"><span style="color: #ababab">待分配</span></c:if>
                            </td>
                            <td><fmt:formatDate value="${exception.startTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                            <td>
                                <c:if test="${exception.status == 0}"><span class="layui-btn layui-btn-danger" style="border-radius: 4px"> 未处理 </span></c:if>
                                <c:if test="${exception.status == 1}"><span class="layui-btn layui-btn-normal" style="border-radius: 4px"> 处理中 </span></c:if>
                                <c:if test="${exception.status == 2}"><span class="layui-btn" style="border-radius: 4px;background-color: #009688"> 已完成 </span></c:if>
                            </td>
                            <td>
                                <a title="编辑" href="javascript:;" onclick="repair_edit('编辑','/repair/showInsertPage.html','${exception.id}','1000','600')"
                                   class="ml-5" style="text-decoration:none">
                                    <i class="layui-icon">&#xe642;</i>
                                </a>
                                <a title="删除" href="javascript:;" onclick="repair_del(this,'${exception.id}')"
                                   style="text-decoration:none">
                                    <i class="layui-icon">&#xe640;</i>
                                </a>
                            </td>
                        </tr>
                    </c:forEach>
                </c:if>
                <c:if test="${empty pageInfo.list}">
                    <tr>
                        <td colspan="9" style="color:#bbbaba">暂无记录~</td>
                    </tr>
                </c:if>
            </tbody>
        </table>
    </div>
    <div id="page">
        <ul class="pagination" style="margin: 80px 0 0 0">
            <li><a href="/repair/searchExceptionToPage.html?url=repairlist&typeId=1">首页</a></li>
            <c:if test="${pageInfo.pageNum == 1}">
                <li class="disabled"><span>上一页</span></li>
            </c:if>
            <c:if test="${pageInfo.pageNum != 1}">
                <li><a href="/repair/searchExceptionToPage.html?url=repairlist&typeId=1&pageNum=${pageInfo.prePage}">上一页</a></li>
            </c:if>
            <c:forEach items="${pageInfo.navigatepageNums}" var="i">
                <c:if test="${i == pageInfo.pageNum}">
                    <li class="active"><span>${pageInfo.pageNum}</span></li>
                </c:if>
                <c:if test="${i!=pageInfo.pageNum}">
                    <li><a href="/repair/searchExceptionToPage.html?url=repairlist&typeId=1&pageNum=${i}">${i}</a></li>
                </c:if>
            </c:forEach>
            <c:if test="${pageInfo.pageNum == pageInfo.pages}">
                <li class="disabled"><span>下一页</span></li>
            </c:if>
            <c:if test="${pageInfo.pageNum != pageInfo.pages}">
                <li><a href="/repair/searchExceptionToPage.html?url=repairlist&typeId=1&pageNum=${pageInfo.nextPage}">下一页</a></li>
            </c:if>
            <li><a href="/repair/searchExceptionToPage.html?url=repairlist&typeId=1&pageNum=${pageInfo.pages}" style="border-radius: 4px">末页</a></li>
            <li>
                <form id="jumpPageForm" class="layui-form x-center" action="/repair/searchExceptionToPage.html" style="display: inline-block;margin-left: 20px">
                    <div class="layui-form-pane">
                        <input type="hidden" name="url" value="repairlist">
                        <input type="hidden" name="typeId" value="1">
                        <div class="layui-input-inline" style="width: 100px;margin-right: 10px">
                            <input type="text" name="pageNum"  placeholder="页数" autocomplete="off" class="layui-input" style="margin-bottom: 10px;height: 33px;border-radius: 4px">
                        </div>
                        <div class="layui-input-inline" style="margin-bottom: 10px">
                            <button id="jumpPageBtn" class="layui-btn" lay-filter="jumpPage" style="height: 34px;line-height:28px;padding: 0 14px;border-radius: 4px;"><i class="layui-icon" style="font-size: 14px">跳转</i></button>
                        </div>
                    </div>
                </form>
            </li>
        </ul>
    </div>
</div>
<script src="/lib/layui/layui.js" charset="utf-8"></script>
<script src="/js/x-layui.js" charset="utf-8"></script>
<script src="/js/jquery.min.js" charset="utf-8"></script>
<script src="/js/jquery.table2excel.min.js"></script>
<script>
    layui.use(['laydate','element','laypage','layer','form'], function(){
        $ = layui.jquery;//jquery
        laydate = layui.laydate;//日期插件
        lement = layui.element();//面包导航
        laypage = layui.laypage;//分页
        layer = layui.layer;//弹出层
        form = layui.form();

        $('#jumpPageBtn').click(function () {
            var pageNum = $("input[name='pageNum']").val();
            if (pageNum==""){
                layer.msg('请输入页数！',{icon:5,time:2000});return false;
            }
            var n = /^[0-9]*$/;
            var re = new RegExp(n);
            if (!re.test(pageNum)){
                layer.msg('只能输入数字！',{icon:5,time:2000});return false;
            }
            $('#jumpPageForm').submit();
        });

        $("dd").click(function () {
            if($('.layui-this').attr("lay-value")!= -1){
                $("input[name='userName']").attr("disabled",false);
            }else{
                $("input[name='userName']").attr("disabled",true);
            }
        });

        $('#checkedAll').click(function () {
            if ($(this).is(":checked")){
                $("input[type='checkbox']:not(:first)").prop("checked",true)
            }else{
                $("input[type='checkbox']:not(:first)").prop("checked",false)
            }
        });
    });

    //批量删除提交
    function delAll () {
        layer.confirm('确认要删除吗？',function(index){
            var idStr = "";

            $("input[type='checkbox']:not(:first)").each(function () {
                if ($(this).is(":checked")){
                    idStr+=$(this).val()+",";
                }
            })
            $.ajax({
                type:"post",
                url:"/repair/deleteException.action",
                data:{id:idStr},
                dataType:"json",
                success:function(data){
                    if(data.status==1){
                        layer.msg(data.info,{icon:6,time:1000});
                        setTimeout(function(){
                            window.location.reload();
                        },1000);return false;
                    } else{
                        layer.msg(data.info,{icon:5,time:1000});return false;
                    }
                }
            });
        });
    }

    function question_show (argument) {
        layer.msg('可以跳到前台具体问题页面',{icon:1,time:1000});
    }
    //编辑
    function repair_edit (title,url,id,w,h) {
        url =url+"?id="+id+"&url=repairadd";
        x_admin_show(title,url,w,h);
    }

    /*删除*/
    function repair_del(obj,id){
        layer.confirm('确认要删除吗？',{icon:3,title:'提示信息'},function(index){
            $.ajax({
                type:"post",
                url:"/repair/deleteException.action",
                data:{id:id},
                dataType:"json",
                success:function(data){
                    if(data.status==1){
                        layer.msg(data.info,{icon:6,time:1000});
                        setTimeout(function(){
                            window.location.reload();
                        },1000);return false;
                    } else{
                        layer.msg(data.info,{icon:5,time:1000});return false;
                    }
                }
            });
        });
    }
    /*导表*/
    function downLoadFile(){
        layer.confirm('确认要导出当前数据？',{icon:3,title:'提示信息'},function(index){
            $("#repairList").table2excel({
                exclude: ".noExl",
                name: "Excel Document Name",
                columns:"0",
                filename: "工作表",
                exclude_img: true,
                exclude_links: true,
                exclude_inputs: true
            });
            layer.close(index);
        });
    }
</script>
</body>
</html>